local wen__maimai = fk.CreateSkill {
  name = "wen__maimai",
}

Fk:loadTranslationTable{
  ["wen__maimai"] = "买卖",
  [":wen__maimai"] = "每回合限一次，你可以将两张类型相同的牌当任意一张智囊牌使用。",
  ["#wen__maimai"] = "买卖：请选择两张类型相同的牌，当作任意一张智囊牌使用",
}

wen__maimai:addEffect("viewas", {
  pattern = "dismantlement,ex_nihilo,nullification",  -- 匹配3张指定智囊牌（过河拆桥/无中生有/无懈可击）
  prompt = "#wen__maimai",

  interaction = function(self, player)
    local all_names = {"dismantlement", "ex_nihilo", "nullification"}
    local names = player:getViewAsCardNames(wen__maimai.name, all_names)
    if #names == 0 then return end
    return UI.CardNameBox {
      choices = names,
      all_choices = all_names
    }
  end,

  handly_pile = true,

  card_filter = function(self, player, to_select, selected)  

    return #selected < 2 and (
    #selected == 0 or
    Fk:getCardById(to_select).type == Fk:getCardById(selected[1]).type
    )
  end,

  view_as = function(self, player, cards)
    if #cards ~= 2 or not self.interaction.data then return end

    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = wen__maimai.name

    return card
  end,

  enabled_at_play = function(self, player)
    return player:usedSkillTimes(wen__maimai.name, Player.HistoryTurn) == 0
  end,

  enabled_at_response = function(self, player, response)
    return player:usedSkillTimes(wen__maimai.name, Player.HistoryTurn) == 0
  end,
})

return wen__maimai